package Top200;

/**
 * @author zhangmin
 * @create 2022-02-22 11:50
 * 先对角线反转。然后左右翻转
 */
public class rotate48 {
    public void rotate(int[][] matrix) {
        int n=matrix.length;
        //先对角线反转
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                int t=matrix[i][j];
                matrix[i][j]=matrix[j][i];
                matrix[j][i]=t;
            }
        }
        //左右交换
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n / 2; j++) {
                int temp=matrix[i][j];
                matrix[i][j]=matrix[i][n-j-1];
                matrix[i][n-j-1]=temp;
            }
        }
    }
}
